﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 护士工作站
{
    public partial class 处方作废 : Form
    {
        public 处方作废()
        {
            InitializeComponent();
        }

        private void tSButton_tc_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        public void Fill()
        {
            SqlDataAdapter da;
            DataSet ds;




            string sql = string.Format("select * from[hushigongzuozhan1].[dbo].[Recipe] where HosNo = '{0}'", txtzhuyuanhao.Text.Trim());


            using (SqlConnection conn = new SqlConnection(DBHelper.connString))
            {
                da = new SqlDataAdapter(sql, conn);
                ds = new DataSet();
                da.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];
            }




        }


        private void tSButton_sx_Click(object sender, EventArgs e)
        {
            Fill();
            string connString = DBHelper.connString;
            string sqlstr = string.Format("select * from [hushigongzuozhan1].[dbo].[Recipe],[hushigongzuozhan1].[dbo].[Warn],[hushigongzuozhan1].[dbo].[Patient] where [hushigongzuozhan1].[dbo].[Recipe].HosNo = [hushigongzuozhan1].[dbo].[Warn].HosNo and  [hushigongzuozhan1].[dbo].[Recipe].HosNo = [hushigongzuozhan1].[dbo].[Patient] .HosNo  and  [hushigongzuozhan1].[dbo].[Recipe].HosNo = '{0}'", txtzhuyuanhao.Text.Trim());
            using (SqlConnection conn = new SqlConnection(connString))
            {
                SqlCommand cmd = new SqlCommand(sqlstr, conn);
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    txtleibie.Text = dr["RecProject"].ToString();
                    txtdate.Text = dr["WarBegindate"].ToString();

                    txtname.Text = dr["PatName"].ToString();
                    txtfushu.Text = dr["RecNumber"].ToString();




                }
                dr.Close();
            }
        }

        private void tSButton_sc_Click(object sender, EventArgs e)
        {
            string id;



            id = dataGridView1.CurrentRow.Cells[9].Value.ToString();


            if (MessageBox.Show("确定要删除吗", " 询问", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                return;


            using (SqlConnection conn = new SqlConnection(DBHelper.connString))
            {
                string sql = string.Format("delete from Recipe where chufanghao = {0}", id);
                SqlCommand cmd = new SqlCommand(sql, conn);
                conn.Open();
                int n = Convert.ToInt32(cmd.ExecuteNonQuery());
                if (n != 1)
                {
                    MessageBox.Show("删除失败");
                }
                else
                {
                    MessageBox.Show("删除成功");
                }


            }

            Fill();
        }
    }
}
